// pages/confirm/confirm.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    display:"none",
    _num: 1,
    order_no:''
  },
  liuyan:function(e){
      this.setData({
        liuyan:e.detail.value
      })
  },
  show_payment:function(){
    let that=this;
    wx.request({
      url: app.data.Url +'order/insertOrder',
      data:{
        goods_data:{
          goodsid:that.data.goodsid,
          number:that.data.num,
          remark: that.data.liuyan,
          rule:that.data.rule
        },
        uid: wx.getStorageSync('userInfo').uid
      },
      method:'post',
      success:function(res){
        that.setData({
          order_no: res.data.data.order_no
        })
      }
    })
    wx.request({
      url: '',
      data:{

      },
      method:'get',
      success:function(res){

      }
    })
    this.setData({
      display:"block"
    })

  },
  hideview: function () {
    let  that=this;
    
    wx.request({
      url: app.data.Url+'order/orderPayParams',
      data:{
        order_no:that.data.order_no,
        title:'智慧社区订单支付',
        uid:wx.getStorageSync('userInfo').uid
      },
      method:'post',
      success:function(res){
        console.log(res)
        wx.requestPayment({
          'timeStamp': res.data.data.weixin.timeStamp,
          'nonceStr': res.data.data.weixin.nonceStr,
          'package': res.data.data.weixin.package,
          'signType': 'MD5',
          'paySign': res.data.data.weixin.paySign,
          'success': function (res) {
              
            },
          'fail': function (res) {

            }
        })
      }
    })
    this.setData({
      display: "none"
    })
  },
  focus_click: function (e) {
    this.setData({
      _num: e.target.dataset.num
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    wx.request({
      url: app.data.Url +'goods/detail',
      data:{
        goodsid:options.goodsid
      },
      success:function(res){

        that.setData({
          detail: res.data.data,
          num:options.num,
          money: (parseFloat(options.price*100) * parseFloat(options.num) )/100,
          price: options.price ,
          goodsid:options.goodsid,
          rule:options.guige,
          pic: res.data.data.pic
        })
     
      }
    })
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    wx.request({
      url: app.data.Url + 'address/get_defaultadd',
      data: {
        uid: wx.getStorageSync('userInfo').uid,
      },
      method: 'get',
      success: function (res) {
        that.setData({
          add: res.data.data
        })
        console.log(res.data.data);

        if (!res.data.data.city){
         wx.showModal({
           title: '提示',
           content: '请添加默认地址',
           showCancel:false,
           success:function(){
             wx.navigateTo({
               url: '/pages/address/address',
             })
           }
         })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})